package org.jftstool.auxiliar;

import java.io.ByteArrayInputStream;
import java.util.Date;

import org.jftstool.fileParserFramework.FileFormatHandler;
import org.jftstool.fileParserFramework.contentHandler.BodyResultHandler;
import org.jftstool.fileParserFramework.exceptions.FileHandlerException;
import org.jftstool.fileParserFramework.metadata.DocumentMetaData;
import org.jftstool.indexer.document.DBDocument;
import org.jftstool.indexer.document.constructor.DBDocumentsExtractor;
import org.jftstool.indexer.document.constructor.DefaultDBDocumentExtractor;
import org.jftstool.indexer.document.exceptions.DBDocumentExtractorException;

public class DBDocumentExtractorTest2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			DBDocumentsExtractor extractor = new DefaultDBDocumentExtractor();
			extractor.createConnection("MySql");
			extractor.createStatement("DefaultQuery");
			
			DBDocument doc = null;
			FileFormatHandler handler = null;
			DocumentMetaData metaData = null;
			BodyResultHandler result = null;
			handler = new FileFormatHandler();			
			Date start = null;
			Date end = null;
			
			start = new Date();
			while ((doc = extractor.next()) != null){
				if (doc.getDocument() != null){
					metaData = new DocumentMetaData();
					result = new BodyResultHandler();					
					handler.getDocument(new ByteArrayInputStream(doc.getDocument()), result, metaData);
					System.out.println(result);
					System.out.println(metaData.getProperty(DocumentMetaData.CONTENT_LANGUAGE));
				}
			}
			end = new Date();
			System.out.println("Elapsed time: " + (end.getTime() - start.getTime()) + " mseg" );			
		}
		catch (DBDocumentExtractorException e) {
			e.printStackTrace();
		}
		catch (FileHandlerException e) {
			e.printStackTrace();
		}
	}
}
